package com.ht.temp.service.impl;

import com.ht.temp.entity.MinReport;
import com.ht.temp.mapper.MinReportMapper;
import com.ht.temp.service.IMinReportService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author mayke_zhou
 * @since 2018-12-24
 */
@Service
public class MinReportServiceImpl extends ServiceImpl<MinReportMapper, MinReport> implements IMinReportService {

    @Autowired
    private MinReportMapper minReportMapper;

    @Override
    public MinReport getMinReportByHoursAvg(Integer deviceId) {
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH");
        LocalDateTime localDateTime3 = LocalDateTime.now();
        String nowtime = df.format(localDateTime3);
        //MinReport minReport = minReportMapper.selectMinReportByHoursAvg(localTime,localTime,deviceId);
        //System.out.println("minReport.toString()"+ minReportMapper.selectMinReportByHoursAvg(localTime,localTime,deviceId).toString());
        return minReportMapper.selectMinReportByHoursAvg(nowtime,nowtime,deviceId);
    }

    @Override
    public List<MinReport> getMinReportByHours(Integer deviceId, String startTime, String endTime) {
        System.out.println(startTime.substring(0,startTime.length()-3)+"/"+endTime.substring(0,startTime.length()-3));
//        LocalDateTime start = LocalDateTime.parse(startTime,df);
//        LocalDateTime end = LocalDateTime.parse(endTime,df);
        String sTime = startTime.substring(0,startTime.length()-3);
        String eTime = endTime.substring(0,startTime.length()-3);
        return minReportMapper.selectMinReportByHours(sTime,eTime,deviceId);
    }
}
